package com.enation.app.shop.front.policyInsurance.service.impl;

import com.enation.app.shop.front.api.inpolicy.entity.InPolicy;
import com.enation.app.shop.front.policyInsurance.service.InpolicyFrameManageMapper;
import com.enation.framework.database.IDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class InpolicyFrameManageMapperService implements InpolicyFrameManageMapper {
    @Autowired
    private IDaoSupport iDaoSupport;

    @Override
    public List<InPolicy> getAllInPolicyInfo(int user_id){
        String sql = "SELECT * from rbt_inpolicy where user_id=? and is_policy=1 and `status`not in (7) ORDER BY begin_time desc";
        return this.iDaoSupport.queryForList(sql,InPolicy.class,user_id);
    }

    @Override
    public List<InPolicy> getUnpaidInpolicyInfo(int user_id) {
        String sql = "select * from rbt_inpolicy w where w.user_id=? and is_policy=1 and w.`status`=4 ORDER BY begin_time desc";
        return this.iDaoSupport.queryForList(sql,InPolicy.class,user_id);
    }

    @Override
    public List<InPolicy> getCheckInpolicyInfo(int user_id) {
        String sql = "select * from rbt_inpolicy w where w.`status` in (1,3) and is_policy=1 and w.user_id=? ORDER BY begin_time desc";
        return this.iDaoSupport.queryForList(sql,InPolicy.class,user_id);
    }

    @Override
    public List<InPolicy> getBearInpolicyInfo(int user_id) {
        String sql = "select * from rbt_inpolicy w where w.`status`=6 and is_policy=1 and w.user_id=? ORDER BY begin_time desc";
        return this.iDaoSupport.queryForList(sql,InPolicy.class,user_id);
    }

    @Override
    public List<InPolicy> getHistoryInpolicyInfo(int user_id) {
        String sql = "select * from rbt_inpolicy w where w.`status`=7 and is_policy=1 and w.user_id=? ORDER BY begin_time desc";
        return this.iDaoSupport.queryForList(sql,InPolicy.class,user_id);
    }

    @Override
    public int addInPolicy(InPolicy inPolicy) {
        this.iDaoSupport.insert("rbt_inpolicy",inPolicy);
        return 1;
    }

    public InPolicy getBytinPolicy_id(int inPolicy_id){
        String sql = "select * from rbt_inpolicy r where r.warranty_id=?";
        return iDaoSupport.queryForList(sql,InPolicy.class,inPolicy_id).get(0);
    }
}
